package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Comment;
import cn.wolfcode.mapper.CommentMapper;
import cn.wolfcode.qo.CommentQuery;
import cn.wolfcode.service.ICommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* 评论服务接口实现
*/
@Service
@Transactional
public class CommentServiceImpl extends ServiceImpl<CommentMapper,Comment> implements ICommentService  {

    @Override
    public IPage<Comment> queryPage(CommentQuery qo) {
        IPage<Comment> page = new Page<>(qo.getCurrentPage(), qo.getPageSize());
        QueryWrapper<Comment> wrapper = Wrappers.<Comment>query();
        return super.page(page, wrapper);
    }

    @Override
    public List<Comment> getByMessageBoardId(Long messageBoardId) {
        QueryWrapper<Comment> wrapper = new QueryWrapper<>();
        wrapper.eq("messageBoard_id",messageBoardId);
        List<Comment> list = list(wrapper);
        return list;
    }
}
